<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use Overtrue\Wechat\Auth;

class UserController extends Controller
{

    public function login(Request $req){//微信登录
        if($req->session()->get('user')){
            return redirect('/');
        }
        $auth = new Auth(env('WX_APPID'), env('WX_SECRET'));
        $to = 'http://vyetqx7v4d.proxy.qqbrowser.cc/login'; //微信服务器向本地url，post数据的地址
        $user = $auth->authorize($to);//获得用户信息
        $req->session()->put('user', $user->all());//把用户信息写入session中
        //return back();//返回到调用此页面的页面
        return back();


    }

    public function logout(Request $req){
        if($req->session()->get('user')) {
            $req->session()->forget('user');
            echo 'logout';
        }

    }


}
